package com.jz.community.moduleshopping.shopCart.adapter;

import android.support.annotation.Nullable;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jz.community.basecomm.constant.AppConstants;
import com.jz.community.basecomm.utils.BaseImageLoaderUtils;
import com.jz.community.basecomm.utils.CharacterUtils;
import com.jz.community.basecomm.utils.ConverterUtils;
import com.jz.community.basecomm.utils.Preconditions;
import com.jz.community.basecomm.utils.RxTextTool;
import com.jz.community.basecomm.utils.SHelper;
import com.jz.community.moduleshopping.R;
import com.jz.community.moduleshopping.shopCart.bean.CartGoodInfo;

import java.util.List;

/**
 * 失效购物列表
 */
public class InvalidCartItemAdapter extends BaseQuickAdapter<CartGoodInfo, BaseViewHolder> {


    public InvalidCartItemAdapter(@Nullable List<CartGoodInfo> data) {
        super(R.layout.module_shopping_item_cart_invalid_item_layout, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, CartGoodInfo item) {
        showGoodsInfo(helper, item);
    }

    /**
     * 显示商品信息
     *
     * @param helper
     * @param cartInfosBean
     */
    private void showGoodsInfo(BaseViewHolder helper, CartGoodInfo cartInfosBean) {
        TextView cartItemPriceDisPriceTv = helper.getView(R.id.cart_item_price_disPrice_tv);
        helper.setText(R.id.cart_item_name, cartInfosBean.getGoodsName());
        helper.setText(R.id.cart_item_nums, cartInfosBean.getNum() + "");
        helper.setText(R.id.cart_item_spec, cartInfosBean.getSkuName());
        if (!Preconditions.isNullOrEmpty(cartInfosBean.getDiscountPrice())) {
            helper.setText(R.id.cart_item_price, AppConstants.MONEY + CharacterUtils.roundByGoodPrice(ConverterUtils.toDouble(cartInfosBean.getDiscountPrice())));
            RxTextTool.getBuilder("").append(AppConstants.MONEY + CharacterUtils.roundByGoodPrice(ConverterUtils.toDouble(cartInfosBean.getPrice()))).setStrikethrough().into(cartItemPriceDisPriceTv);
            SHelper.vis(cartItemPriceDisPriceTv);
        } else {
            helper.setText(R.id.cart_item_price, AppConstants.MONEY + CharacterUtils.roundByGoodPrice(ConverterUtils.toDouble(cartInfosBean.getPrice())));
            SHelper.gone(cartItemPriceDisPriceTv);
        }
        BaseImageLoaderUtils.getInstance().loadDefaltImage(mContext, helper.getView(R.id.cart_item_img), cartInfosBean.getIcon());
    }
}
